package com.guodu.dao.impl;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.guodu.base.BaseDao;
import com.guodu.dao.PurchaseBiddingPlantzDao;
import com.guodu.entity.PurchaseBiddingPlantz;
import com.guodu.entity.PurchasebiddingtzStatus;
import com.guodu.entity.Units;
import com.guodu.vo.PurchaseBiddingPlantzQueryVo;
import com.guodu.vo.PurchaseBiddingPlantzVo;

@Repository("purchaseBiddingPlantzDao")
public class PurchaseBiddingPlantzDaoImpl extends BaseDao implements PurchaseBiddingPlantzDao {

	@Override
	public long findSizeByVo(PurchaseBiddingPlantzQueryVo pbpq, Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("select count(*) from PurchaseBiddingPlantz m where 1=1");
		if(pbpq!=null){
			if(pbpq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pbpq.getFunitsId()+" ) or m.unitsId ="+pbpq.getFunitsId()+" )");
			}
			if(pbpq.getUnitsId()!=null && !"".equals(pbpq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pbpq.getUnitsId()+"");
			}
			if (pbpq.getProjectName()!=null && !"".equals(pbpq.getProjectName())) {
				hql.append(" and projectName like '%"+pbpq.getProjectName()+"%' ");
			}
			if (pbpq.getProjecttype()!=null && !"".equals(pbpq.getProjecttype())) {
				hql.append(" and projectType like '%"+pbpq.getProjecttype()+"%' ");
			}
			if (pbpq.getProjectSituation()!=null && !"".equals(pbpq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pbpq.getProjectSituation()+"%' ");
			}
			if (pbpq.getSectionName()!=null && !"".equals(pbpq.getSectionName())) {
				hql.append(" and sectionName like '%"+pbpq.getSectionName()+"%' ");
			}
			if (pbpq.getSecName()!=null && !"".equals(pbpq.getSecName())) {
				hql.append(" and secName like '%"+pbpq.getSecName()+"%' ");
			}
			if (pbpq.getSecUnits()!=null && !"".equals(pbpq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pbpq.getSecUnits()+"%' ");
			}
			if (pbpq.getSecClassification()!=null && !"".equals(pbpq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pbpq.getSecClassification()+"%' ");
			}
			if (pbpq.getProcurementMethod()!=null && !"".equals(pbpq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pbpq.getProcurementMethod()+"%' ");
			}
			if(pbpq.getPurchaseYears()!=null&&pbpq.getPurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') >= TO_DATE('"+pbpq.getPurchaseYears()+"','yyyy')");
			}
			if(pbpq.getEpurchaseYears()!=null&&pbpq.getEpurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') <= TO_DATE('"+pbpq.getEpurchaseYears()+"','yyyy')");
			}
			if(pbpq.getCreateBeginTime()!=null&&pbpq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pbpq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getCreateEndTime()!=null&&pbpq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pbpq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcbeginTime()!=null && !"".equals(pbpq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pbpq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcendTime()!=null && !"".equals(pbpq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pbpq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getStatus()!=null&&pbpq.getStatus().trim().length()>0&&!pbpq.getStatus().equals("5")){
				hql.append(" and status ="+pbpq.getStatus());
			}
			if (pbpq.getAdjustment()!=null && !"".equals(pbpq.getAdjustment())) {
				hql.append("    and adjustment like '%"+pbpq.getAdjustment()+"%'");
			}
		}
		if(units==null){
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append(" and status=3");
		}else if(units.getUnitsLevel()==2L){
			hql.append(" and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}
		
		return super.findInt(hql.toString());
	}
	@Override
	public void examinAll(PurchaseBiddingPlantzQueryVo pbpq, Units units) {
		StringBuffer hql = new StringBuffer();
		if(units==null){
			hql.append("update from PurchaseBiddingPlantz m set m.status=3 where m.status=0 ");		
		}
		if(pbpq!=null){
			if(pbpq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pbpq.getFunitsId()+" ) or m.unitsId ="+pbpq.getFunitsId()+" )");
			}
			if(pbpq.getUnitsId()!=null && !"".equals(pbpq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pbpq.getUnitsId()+"");
			}
			if (pbpq.getProjectName()!=null && !"".equals(pbpq.getProjectName())) {
				hql.append(" and projectName like '%"+pbpq.getProjectName()+"%' ");
			}
			if (pbpq.getProjecttype()!=null && !"".equals(pbpq.getProjecttype())) {
				hql.append(" and projectType like '%"+pbpq.getProjecttype()+"%' ");
			}
			if (pbpq.getProjectSituation()!=null && !"".equals(pbpq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pbpq.getProjectSituation()+"%' ");
			}
			if (pbpq.getSectionName()!=null && !"".equals(pbpq.getSectionName())) {
				hql.append(" and sectionName like '%"+pbpq.getSectionName()+"%' ");
			}
			if (pbpq.getSecName()!=null && !"".equals(pbpq.getSecName())) {
				hql.append(" and secName like '%"+pbpq.getSecName()+"%' ");
			}
			if (pbpq.getSecUnits()!=null && !"".equals(pbpq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pbpq.getSecUnits()+"%' ");
			}
			if (pbpq.getSecClassification()!=null && !"".equals(pbpq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pbpq.getSecClassification()+"%' ");
			}
			if (pbpq.getProcurementMethod()!=null && !"".equals(pbpq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pbpq.getProcurementMethod()+"%' ");
			}
			if(pbpq.getPurchaseYears()!=null&&pbpq.getPurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') >= TO_DATE('"+pbpq.getPurchaseYears()+"','yyyy')");
			}
			if(pbpq.getEpurchaseYears()!=null&&pbpq.getEpurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') <= TO_DATE('"+pbpq.getEpurchaseYears()+"','yyyy')");
			}
			if(pbpq.getCreateBeginTime()!=null&&pbpq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pbpq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getCreateEndTime()!=null&&pbpq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pbpq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcbeginTime()!=null && !"".equals(pbpq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pbpq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcendTime()!=null && !"".equals(pbpq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pbpq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getStatus()!=null&&pbpq.getStatus().trim().length()>0&&!pbpq.getStatus().equals("5")){
				hql.append(" and status ="+pbpq.getStatus());
			}
			if (pbpq.getAdjustment()!=null && !"".equals(pbpq.getAdjustment())) {
				hql.append("    and adjustment like '%"+pbpq.getAdjustment()+"%'");
			}
		}
		if(units==null){
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append(" and status=3");
		}else if(units.getUnitsLevel()==2L){
			hql.append(" and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}
		
		super.executeUpdate(hql.toString());		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PurchaseBiddingPlantz> findByVo(PurchaseBiddingPlantzQueryVo pbpq,
			Units units, int curPage, int pageSize) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("from PurchaseBiddingPlantz m where 1=1");
		if(pbpq!=null){
			if(pbpq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pbpq.getFunitsId()+" ) or m.unitsId ="+pbpq.getFunitsId()+" )");
			}
			if(pbpq.getUnitsId()!=null && !"".equals(pbpq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pbpq.getUnitsId()+"");
			}
			if (pbpq.getProjectName()!=null && !"".equals(pbpq.getProjectName())) {
				hql.append(" and projectName like '%"+pbpq.getProjectName()+"%' ");
			}
			if (pbpq.getProjecttype()!=null && !"".equals(pbpq.getProjecttype())) {
				hql.append(" and projectType like '%"+pbpq.getProjecttype()+"%' ");
			}
			if (pbpq.getProjectSituation()!=null && !"".equals(pbpq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pbpq.getProjectSituation()+"%' ");
			}
			if (pbpq.getSectionName()!=null && !"".equals(pbpq.getSectionName())) {
				hql.append(" and sectionName like '%"+pbpq.getSectionName()+"%' ");
			}
			if (pbpq.getSecName()!=null && !"".equals(pbpq.getSecName())) {
				hql.append(" and secName like '%"+pbpq.getSecName()+"%' ");
			}
			if (pbpq.getSecUnits()!=null && !"".equals(pbpq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pbpq.getSecUnits()+"%' ");
			}
			if (pbpq.getSecClassification()!=null && !"".equals(pbpq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pbpq.getSecClassification()+"%' ");
			}
			if (pbpq.getProcurementMethod()!=null && !"".equals(pbpq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pbpq.getProcurementMethod()+"%' ");
			}
			if(pbpq.getPurchaseYears()!=null&&pbpq.getPurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') >= TO_DATE('"+pbpq.getPurchaseYears()+"','yyyy')");
			}
			if(pbpq.getEpurchaseYears()!=null&&pbpq.getEpurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') <= TO_DATE('"+pbpq.getEpurchaseYears()+"','yyyy')");
			}
			if(pbpq.getCreateBeginTime()!=null&&pbpq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pbpq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getCreateEndTime()!=null&&pbpq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pbpq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcbeginTime()!=null && !"".equals(pbpq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pbpq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcendTime()!=null && !"".equals(pbpq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pbpq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getStatus()!=null&&pbpq.getStatus().trim().length()>0&&!pbpq.getStatus().equals("5")){
				hql.append(" and status ="+pbpq.getStatus());
			}
			if (pbpq.getAdjustment()!=null && !"".equals(pbpq.getAdjustment())) {
				hql.append("    and adjustment like '%"+pbpq.getAdjustment()+"%'");
			}
		}
		if(units==null){
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append(" and status=3");
		}else if(units.getUnitsLevel()==2L){
			hql.append(" and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}
		
		hql.append(" order by purchaseId desc");
		return super.findPages(hql.toString(), curPage, pageSize);
	}

	@Override
	public void save(PurchaseBiddingPlantz purchaseBiddingPlantz) {
		// TODO Auto-generated method stub
		super.save(purchaseBiddingPlantz);
	}

	@Override
	public PurchaseBiddingPlantz findById(String purchaseId) {
		// TODO Auto-generated method stub
		return (PurchaseBiddingPlantz) super.findById(PurchaseBiddingPlantz.class, purchaseId);
	}

	@Override
	public void update(PurchaseBiddingPlantz purchaseBiddingPlantz) {
		// TODO Auto-generated method stub
		super.update(purchaseBiddingPlantz);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PurchasebiddingtzStatus> findStatus(String purchaseId) {
		// TODO Auto-generated method stub
		return super.findByProperty(PurchasebiddingtzStatus.class, "purchaseId", purchaseId);
	}

	@Override
	public void changeStatus(List<PurchasebiddingtzStatus> entities) {
		// TODO Auto-generated method stub
		super.saveAll(entities);
	}

	@Override
	public void examine(String ids, Long status) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("update PurchaseBiddingPlantz set status =");
		hql.append(status);
		hql.append(" where purchaseId in (");
		hql.append(ids);
		hql.append(")");
		super.executeUpdate(hql.toString());
	}

	@Override
	public void delByIds(String[] delIds) {
		// TODO Auto-generated method stub
		super.deleteAllById(PurchaseBiddingPlantz.class, delIds);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PurchaseBiddingPlantz> findAllByVo(
			PurchaseBiddingPlantzQueryVo pbpq, Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("from PurchaseBiddingPlantz m where 1=1");
		if(pbpq!=null){
			if(pbpq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pbpq.getFunitsId()+" ) or m.unitsId ="+pbpq.getFunitsId()+" )");
			}
			if(pbpq.getUnitsId()!=null && !"".equals(pbpq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pbpq.getUnitsId()+"");
			}
			if (pbpq.getProjectName()!=null && !"".equals(pbpq.getProjectName())) {
				hql.append(" and projectName like '%"+pbpq.getProjectName()+"%' ");
			}
			if (pbpq.getProjecttype()!=null && !"".equals(pbpq.getProjecttype())) {
				hql.append(" and projectType like '%"+pbpq.getProjecttype()+"%' ");
			}
			if (pbpq.getProjectSituation()!=null && !"".equals(pbpq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pbpq.getProjectSituation()+"%' ");
			}
			if (pbpq.getSectionName()!=null && !"".equals(pbpq.getSectionName())) {
				hql.append(" and sectionName like '%"+pbpq.getSectionName()+"%' ");
			}
			if (pbpq.getSecName()!=null && !"".equals(pbpq.getSecName())) {
				hql.append(" and secName like '%"+pbpq.getSecName()+"%' ");
			}
			if (pbpq.getSecUnits()!=null && !"".equals(pbpq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pbpq.getSecUnits()+"%' ");
			}
			if (pbpq.getSecClassification()!=null && !"".equals(pbpq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pbpq.getSecClassification()+"%' ");
			}
			if (pbpq.getProcurementMethod()!=null && !"".equals(pbpq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pbpq.getProcurementMethod()+"%' ");
			}
			if(pbpq.getPurchaseYears()!=null&&pbpq.getPurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') >= TO_DATE('"+pbpq.getPurchaseYears()+"','yyyy')");
			}
			if(pbpq.getEpurchaseYears()!=null&&pbpq.getEpurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') <= TO_DATE('"+pbpq.getEpurchaseYears()+"','yyyy')");
			}
			if(pbpq.getCreateBeginTime()!=null&&pbpq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pbpq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getCreateEndTime()!=null&&pbpq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pbpq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcbeginTime()!=null && !"".equals(pbpq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pbpq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcendTime()!=null && !"".equals(pbpq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pbpq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getStatus()!=null&&pbpq.getStatus().trim().length()>0&&!pbpq.getStatus().equals("5")){
				hql.append(" and status ="+pbpq.getStatus());
			}
			if (pbpq.getAdjustment()!=null && !"".equals(pbpq.getAdjustment())) {
				hql.append("    and adjustment like '%"+pbpq.getAdjustment()+"%'");
			}
		}
		if(units==null){
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append(" and status=3");
		}else if(units.getUnitsLevel()==2L){
			hql.append(" and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}
		
		hql.append("order by createTime desc");
		return super.find(hql.toString());
	}

	
	public PurchaseBiddingPlantzVo findAllMoney(
			PurchaseBiddingPlantzQueryVo pbpq, Units units) {
		StringBuffer hql = new StringBuffer("select sum(secEvaluation),sum(sectionEvaluation) from PurchaseBiddingPlantz m where 1=1");
		if(pbpq!=null){
			if(pbpq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pbpq.getFunitsId()+" ) or m.unitsId ="+pbpq.getFunitsId()+" )");
			}
			if(pbpq.getUnitsId()!=null && !"".equals(pbpq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pbpq.getUnitsId()+"");
			}
			if (pbpq.getProjectName()!=null && !"".equals(pbpq.getProjectName())) {
				hql.append(" and projectName like '%"+pbpq.getProjectName()+"%' ");
			}
			if (pbpq.getProjecttype()!=null && !"".equals(pbpq.getProjecttype())) {
				hql.append(" and projectType like '%"+pbpq.getProjecttype()+"%' ");
			}
			if (pbpq.getProjectSituation()!=null && !"".equals(pbpq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pbpq.getProjectSituation()+"%' ");
			}
			if (pbpq.getSectionName()!=null && !"".equals(pbpq.getSectionName())) {
				hql.append(" and sectionName like '%"+pbpq.getSectionName()+"%' ");
			}
			if (pbpq.getSecName()!=null && !"".equals(pbpq.getSecName())) {
				hql.append(" and secName like '%"+pbpq.getSecName()+"%' ");
			}
			if (pbpq.getSecUnits()!=null && !"".equals(pbpq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pbpq.getSecUnits()+"%' ");
			}
			if (pbpq.getSecClassification()!=null && !"".equals(pbpq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pbpq.getSecClassification()+"%' ");
			}
			if (pbpq.getProcurementMethod()!=null && !"".equals(pbpq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pbpq.getProcurementMethod()+"%' ");
			}
			if(pbpq.getPurchaseYears()!=null&&pbpq.getPurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') >= TO_DATE('"+pbpq.getPurchaseYears()+"','yyyy')");
			}
			if(pbpq.getEpurchaseYears()!=null&&pbpq.getEpurchaseYears().trim().length()>0){
				hql.append(" and TO_DATE(years,'yyyy') <= TO_DATE('"+pbpq.getEpurchaseYears()+"','yyyy')");
			}
			if(pbpq.getCreateBeginTime()!=null&&pbpq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pbpq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getCreateEndTime()!=null&&pbpq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pbpq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcbeginTime()!=null && !"".equals(pbpq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pbpq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pbpq.getFcendTime()!=null && !"".equals(pbpq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pbpq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pbpq.getStatus()!=null&&pbpq.getStatus().trim().length()>0&&!pbpq.getStatus().equals("5")){
				hql.append(" and status ="+pbpq.getStatus());
			}
			if (pbpq.getAdjustment()!=null && !"".equals(pbpq.getAdjustment())) {
				hql.append("    and adjustment like '%"+pbpq.getAdjustment()+"%'");
			}
		}
		if(units==null){
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append(" and status=3");
		}else if(units.getUnitsLevel()==2L){
			hql.append(" and exists(select 1 from UserInfo f where f.userId = m.createPeople and f.unitsId  ="+units.getUnitsId()+" )");
		}
		
		PurchaseBiddingPlantzVo p = new PurchaseBiddingPlantzVo();
		List<Object[]> objs = super.find(hql.toString());
		if(objs.size()>0){
			DecimalFormat df = new DecimalFormat("##,###.##");
			try {
				if(objs.get(0)[0]!=null){
				p.setAllMoney1(df.format(df.parse(objs.get(0)[0].toString())));
				}
				if(objs.get(0)[1]!=null){
				p.setAllMoney2(df.format(df.parse(objs.get(0)[1].toString())));
				}
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return p;
	}

	

	
}
